<?php 
//引进配置信息
include '../include/init.php';
//引入数据库配置信息
include '../include/mysql.config.php';
//引入公共函数
include '../include/common.fun.php';
islogin();
if($_GET){
	$id=isset($_GET['id'])?$_GET['id']+0:0;
	$sql="SELECT * from wd_admin where admin_id=$id";
	$admin=$db->getOne($sql);
}



if ($_POST){
	$title=$_POST['title'];
	$author=md5($_POST['author']);
	$id=$_POST['id'];
	$password1=$_POST['password1'];
	$password2=$_POST['password2'];
	$date=array(
			'admin_name' => $title
		);
	if ($author!=$admin['admin_password']) {
		alert('旧密码不正确');exit;
		
	}elseif ($password1===$password2) {
		$date['admin_password']=md5($password1);
	}else{
		alert('新密码不一致');exit;
	}
	
	
	
	
	$where = 'admin_id='.$id;
	$res = $db->update('wd_admin',$date,$where);
	if($res){
		alert('更新成功','admin_list.php');
	}else{
		alert('更新失败');
	}
}


include 'view/admin_edit.php';